package com.hm.common.utils;

import lombok.AllArgsConstructor;

import java.util.stream.Stream;


/**
* @Description: 平台来源
* @param
* @return
* @throws
* @author Coder编程
* @date 2021/6/17 14:37
*/
public class PartitionUtil {


    /**
     * 判断枚举中是否包含这个dbShare
     * 存在,返回true  ,不存在,返回false
     *
     * @param dbShare 平台 dbShare
     * @return
     */
    public static Boolean checkPlatForm(Integer dbShare) {
        return Stream.of(PlatForm.values()).mapToInt(k -> k.dbShare).anyMatch(k -> k == dbShare);
    }

    /**
     * 通过名称获取平台 dbShare
     *
     * @param platForm 平台枚举名称
     * @return
     */
    public static Integer getPlatForm(String platForm) {
        PlatForm platForms = PlatForm.valueOf(platForm);
        return platForms.dbShare;
    }


    @AllArgsConstructor
    enum PlatForm {
        /**
         * 其他分组
         */
        OTHER("OTHER", 0),
        SITE("WEBSITE", 0),
        CRM("CRM", 1),
        APP("APP", 0);
        private String name;
        private Integer dbShare;
    }

}
